import { axios } from '@/utils/request'

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  const data = { ...parameter }
  delete data.type
  let url = '/oauth/token'
  if (parameter.type === 'user') {
    data.grant_type = 'password'
  } else {
    data.grant_type = 'mobile'
    url = '/mobile/token'
  }
  return axios({
    url: url,
    method: 'post',
    params: data,
    headers: {
      'isToken': false,
      'Authorization': 'Basic Y2hpbGxheC1ib290OmNoaWxsYXgtYm9vdC1zZWNyZXQ='
    }
  })
}

export function getInfo () {
  return axios({
    url: '/sys/user/info',
    method: 'get'
  })
}

export function logout () {
  return axios({
    url: '/token/logout',
    method: 'DELETE'
  })
}

export function menu () {
  return axios({
    url: '/sys/menu/nav',
    method: 'GET'
  })
}

export function sendSmsCode (mobile) {
  return axios({
    url: `/sys/mobile/${mobile}`,
    method: 'GET'
  })
}
